package com.wangsd.web.face.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wangsd.common.basicbean.Result;
import com.wangsd.web.MyController;
import com.wangsd.web.face.entity.Receiver;
import com.wangsd.web.face.service.ReceiverService;
import com.wangsd.web.sys.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author generator
 * @since 2019-09-17
 */
@Api(value = "receiver", tags = "分账账户管理")
@RestController
@RequestMapping("/face/receiver")
public class ReceiverController extends MyController {
    @Autowired
    ReceiverService receiverService;


    @ApiOperation(value = "查询分账账户列表", notes = "查询分账账户列表", httpMethod = "POST")
    @RequestMapping(value = "/selectList/{pageNum}/{pageSize}", method = RequestMethod.POST)
    public Result selectList(@ApiParam(value = "当前页", required = true) @PathVariable("pageNum") Integer pageNum,
                             @ApiParam(value = "每页大小", required = true) @PathVariable("pageSize") Integer pageSize,
                             @RequestBody @ApiParam(name = "receiver", value = "传入json格式") Receiver receiver) {
        SysUser userInfo = getUserInfo();
        if (99 != userInfo.getType()) {
            receiver.setCode(userInfo.getCode());
        }
        IPage<Receiver> receiverIPage = receiverService.selectList(pageNum, pageSize, receiver);
        return Result.success(receiverIPage);
    }


    @ApiOperation(value = "新增或修改分账账户", notes = "新增或修改分账账户", httpMethod = "POST", response = Result.class)
    @RequestMapping(value = "addOrUpdate", method = RequestMethod.POST)
    public Result addOrUpdate(Receiver receiver) {
        SysUser userInfo = getUserInfo();
        receiver.setCode(userInfo.getCode());
        receiverService.addOrUpdate(receiver);
        return Result.success();
    }

    @ApiOperation(value = "删除分账账户信息", notes = "删除分账账户信息", httpMethod = "GET", response = Result.class)
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public Result delete(@ApiParam(value = "分账账户id", required = true) @PathVariable("id") Long id) {
        receiverService.removeById(id);
        return Result.success();
    }

    @ApiOperation(value = "通过id分账账户设备", notes = "通过id分账账户设备", httpMethod = "GET", response = Result.class)
    @GetMapping("/selectById/{id}")
    public Result<Receiver> selectById(@ApiParam(value = "分账账户id", required = true) @PathVariable Long id) {
        Receiver receiver = receiverService.getById(id);
        return Result.success(receiver);
    }

    @ApiOperation(value = "查询服务商下所有分账账户", notes = "查询服务商下所有分账账户", httpMethod = "GET", response = Result.class)
    @GetMapping("/selectAll")
    public Result selectAll() {
        SysUser loginUser = getUserInfo();
        List<Receiver> list = receiverService.selectAllByUserCode(loginUser.getCode());
        return Result.success(list);
    }
}

